#include <hiredis/hiredis.h>
#include <iostream>

int main() {
    redisContext *c = redisConnect("127.0.0.1", 6379);
    if (c == NULL || c->err) {
        if (c) {
            std::cerr << "Connection error: " << c->errstr << std::endl;
            redisFree(c);
        } else {
            std::cerr << "Connection failed" << std::endl;
        }
        return 1;
    }

    // Set a key
    redisReply *reply = (redisReply*)redisCommand(c, "SET %s %s", "key", "value");
    if (reply == NULL) {
        std::cerr << "Failed to execute command" << std::endl;
        redisFree(c);
        return 1;
    }
    freeReplyObject(reply);

    // Get a key
    reply = (redisReply*)redisCommand(c, "GET %s", "key");
    if (reply != NULL && reply->type == REDIS_REPLY_STRING) {
        std::cout << "Value: " << reply->str << std::endl;
    }
    freeReplyObject(reply);

    redisFree(c);
    return 0;
}